<?php

namespace App\Http\Models;

use Illuminate\Database\Eloquent\Builder;

/**
 * @method static self filterCaseTagId(int $case_tag_id)
 *
 * Class Cases
 * @package App\Http\Models
 * @mixin \Illuminate\Database\Query\Builder
 */
class Cases extends BosModel
{
    protected $guarded = [''];

    protected $table = 'cases';

    protected $bosKeyPrefix = 'bym-admin/cases/';

    /**
     * @used-by filterCaseTagId
     * @param Builder $query
     * @param $case_tag_id
     * @return Builder
     */
    public function scopeFilterCaseTagId(Builder $query, $case_tag_id)
    {
        if ($case_tag_id == 0) return $query;

        return $query->where('case_tag_id', $case_tag_id);
    }

    public function setThumbAttribute($data)
    {
        if (!!$data) {
            $bosKey = $this->uploadImages($data, 'cases/thumb/');
            $this->attributes['thumb'] = $bosKey;
        }
    }

    public function getThumbAttribute()
    {

        if (!!$this->attributes['thumb']) {
            return $this->getUrl($this->attributes['thumb']);
        }

    }

}
